/**
 * Created by DoveXL on 2018/12/21.
 */
$(document).ready(function () {
    PersonStatisticFunction();
    TeamNumberStatisticFunction()

});



function PersonStatisticFunction() {
    $.ajax(
        {
            async: true,
            url: "/VolunteerPlatform/PersonInfo/VolunteerAgeStatistics",
            type: "post",
            dataType:"json",
            success: function (data) {
                var agestatistics= eval(data);
                var data1 = [{value:agestatistics.count1, name:'0-20岁'},
                    {value:agestatistics.count2, name:'21-30岁'},
                    {value:agestatistics.count3, name:'31-40岁'},
                    {value:agestatistics.count4, name:'41-50岁'},
                    {value:agestatistics.count5, name:'50岁以上'}]

                var myChart = echarts.init(document.getElementById('main'));

                // 指定图表的配置项和数据
                var option = {
                    title : {
                        text: '小龙人年龄分布示意图',
                        subtext: '真实数据',
                        x:'center'
                    },
                    tooltip : {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        data: ['0-20岁','21-30岁','31-40岁','41-50岁','50岁以上']
                    },
                    series : [
                        {
                            name: '年龄段人数',
                            type: 'pie',
                            radius : '70%',
                            center: ['50%', '50%'],
                            data:data1,
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                // 使用刚指定的配置项和数据显示图表。
                myChart.setOption(option);
            }
        }
    )
}

function TeamNumberStatisticFunction() {
    $.ajax(
        {
            async: true,
            url: "/VolunteerPlatform/PersonInfo/VolunteerTeamNumberStatistics",
            type: "post",
            dataType:"json",
            success: function (data) {
                var teamnumberstatistics= eval(data);
                var data1 = [];
                var data2=[];
                for (var i=0;i<teamnumberstatistics.length;i++)
                {
                    var dataitem = {value:teamnumberstatistics[i].number,name:teamnumberstatistics[i].name};
                    data1.push(dataitem);
                    data2.push(teamnumberstatistics[i].name);
                }

                var myChart = echarts.init(document.getElementById('main1'));
                option = {
                    title : {
                        text: '小龙人单位分布示意图',
                        subtext: '真实数据',
                        x:'center'
                    },
                    tooltip: {
                        trigger: 'item',
                        formatter: "{a} <br/>{b}: {c} ({d}%)"
                    },
                    legend: {
                        orient: 'vertical',
                        x: 'left',
                        data:data2
                    },
                    series: [
                        {
                            name:'单位人数',
                            type:'pie',
                            radius: ['50%', '70%'],
                            avoidLabelOverlap: false,
                            label: {
                                normal: {
                                    show: false,
                                    position: 'center'
                                },
                                emphasis: {
                                    show: true,
                                    textStyle: {
                                        fontSize: '20',
                                        fontWeight: 'bold'
                                    }
                                }
                            },
                            labelLine: {
                                normal: {
                                    show: false
                                }
                            },
                            data:data1
                        }
                    ]
                };
                myChart.setOption(option);
            }
        }
    )

}